ALTER PROCEDURE [dbo].[CPP_Game_WriteScore]
  -- 用户信息
  @dwUserID INT,                -- 用户 I D
  @dwDBQuestID INT,             -- 请求标识
  @dwInoutIndex INT,            -- 进出索引

  -- 变更成绩
  @lVariationScore BIGINT,          -- 用户分数
  @lVariationGrade BIGINT,          -- 用户成绩
  @lVariationInsure BIGINT,         -- 用户银行
  @lVariationRevenue BIGINT,        -- 游戏税收
  @lVariationWinCount INT,          -- 胜利盘数
  @lVariationLostCount INT,         -- 失败盘数
  @lVariationDrawCount INT,         -- 和局盘数
  @lVariationFleeCount INT,         -- 逃跑数目
  @lVariationIntegralCount BIGINT,  -- 游戏积分 
  @lVariationUserMedal INT,         -- 用户奖牌
  @lVariationExperience INT,        -- 用户经验
  @lVariationLoveLiness INT,        -- 用户魅力
  @dwVariationPlayTimeCount INT,    -- 游戏时间

  -- 附加信息
  @cbTaskForward TINYINT,           -- 任务跟进

  -- 属性信息 
  @wKindID INT,     -- 游戏 I D
  @wServerID INT,   -- 房间 I D
  @strClientIP NVARCHAR(15) -- 连接地址
AS
BEGIN

  SET NOCOUNT ON


  -- 用户积分
  UPDATE RYTreasureDB.dbo.GameScoreInfo SET Score=Score+@lVariationScore, Revenue=Revenue+@lVariationRevenue, InsureScore=InsureScore+@lVariationInsure,
    WinCount=WinCount+@lVariationWinCount, LostCount=LostCount+@lVariationLostCount, DrawCount=DrawCount+@lVariationDrawCount,
    FleeCount=FleeCount+@lVariationFleeCount,PlayTimeCount=PlayTimeCount+@dwVariationPlayTimeCount
  WHERE UserID=@dwUserID
  
  -- 房间参数
  UPDATE RYTreasureDB.dbo.GameScoreAttribute SET  
  IntegralCount=IntegralCount+@lVariationIntegralCount,
  WinCount=WinCount+@lVariationWinCount, 
  LostCount=LostCount+@lVariationLostCount, 
  DrawCount=DrawCount+@lVariationDrawCount,
  FleeCount=FleeCount+@lVariationFleeCount 
  WHERE UserID=@dwUserID And ServerID=@wServerID And KindID = @wKindID 
  IF @@ROWCOUNT=0
  BEGIN
    INSERT INTO RYTreasureDB.dbo.GameScoreAttribute (UserID,KindID,ServerID,IntegralCount,WinCount,LostCount,DrawCount,FleeCount) 
    VALUES (@dwUserID,@wKindID,@wServerID,@lVariationIntegralCount,@lVariationWinCount,@lVariationLostCount,@lVariationDrawCount,@lVariationFleeCount)
  END
  
  -- 全局信息
  IF @lVariationExperience>0 OR @lVariationLoveLiness<>0 OR @lVariationUserMedal>0
  BEGIN
    UPDATE RYAccountsDBLink.RYAccountsDB.dbo.AccountsInfo SET Experience=Experience+@lVariationExperience, LoveLiness=LoveLiness+@lVariationLoveLiness,
      UserMedal=UserMedal+@lVariationUserMedal
    WHERE UserID=@dwUserID
  END

  -- 变更记录
  DECLARE @DateID INT
  SELECT @DateID=CAST(CAST(GetDate() AS FLOAT) AS INT) 
  
  -- 存在判断
  IF NOT EXISTS(SELECT * FROM RYTreasureDB.dbo.StreamScoreInfo WHERE DateID=@DateID AND UserID=@dwUserID) 
  BEGIN
    -- 插入记录
    INSERT INTO RYTreasureDB.dbo.StreamScoreInfo(DateID, UserID, WinCount, LostCount, Revenue, PlayTimeCount, OnlineTimeCount, FirstCollectDate, LastCollectDate)
    VALUES(@DateID, @dwUserID, @lVariationWinCount, @lVariationLostCount, @lVariationRevenue, @dwVariationPlayTimeCount, 0, GetDate(), GetDate())   
  END ELSE
  BEGIN
    -- 更新记录
    UPDATE RYTreasureDB.dbo.StreamScoreInfo SET WinCount=WinCount+@lVariationWinCount, LostCount=LostCount+@lVariationLostCount, Revenue=Revenue+@lVariationRevenue,
         PlayTimeCount=PlayTimeCount+@dwVariationPlayTimeCount, LastCollectDate=GetDate()
    WHERE DateID=@DateID AND UserID=@dwUserID   
  END
    
  -- 任务推进
  IF @cbTaskForward=1
  BEGIN
    EXEC RYPlatformDBLink.RYPlatformDB.dbo.GSP_GR_TaskForward @dwUserID,@wKindID,0,@lVariationWinCount,@lVariationLostCount,@lVariationDrawCount  
  END

  RETURN 0
END